-- buy_market_goods
-- created by panyl
-- 冈布奥事件：购买商场物品

local TRIGGER_SCORE  = 345; -- 触发单位积分值

-- 购买商场物品
EventMgr.register("buy_market_goods", event.BUY_GOODS, function(para)
    local goodsId = para.goodsId;

    -- 商品基本信息
    local dbase = MarketM.query(goodsId, "dbase") or {};

    if dbase["slime_event"] ~= "buy_market_goods" then
        -- 不是该子规则关注的事件
        return;
    end

    -- 根据充值额度增加进度
    local chargeAmount = ME.user.dbase:query("user_charge_amount", 0);
    local chargeValue  = MarketM.query(goodsId, "charge_value");

    local progress = math.modf((chargeAmount) / TRIGGER_SCORE) - SlimeEventM.getProgress("buy_market_goods");

    if progress <= 0 then
        return;
    end

    for i = 1, progress do
        -- 累计值达到增加进度，否则不触发
        SlimeEventM.addProgress("buy_market_goods", 1);

        local arr = SlimeEventM.getIdsByRule("buy_market_goods");
        for index = 1, #arr do
            SlimeEventM.triggerEvent(arr[index]);
        end
    end
end);

return {
};
